package com.ktjiaoyu;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;

public class CodeGenerator {
    public static void main(String[] args) {
// 代码生成器
        AutoGenerator mpg = new AutoGenerator();
// 全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir(System.getProperty("user.dir") + "/springboot-mybatiplus-generator/src/main/java");
        globalConfig.setAuthor("jjx");
        globalConfig.setOpen(false);
        mpg.setGlobalConfig(globalConfig);
// 数据源配置
        DataSourceConfig dataSource = new DataSourceConfig();
        dataSource.setUrl("jdbc:mysql://localhost:3306/springboot?serverTimezone=GMT-8&characterEncoding=utf-8");
                dataSource.setDriverName("com.mysql.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");
        mpg.setDataSource(dataSource);
// 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.ktjiaoyu");
        pc.setEntity("pojo"); //设置实体类包名
        mpg.setPackageInfo(pc);
//策略设置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setTablePrefix("sys_"); //设置数据库表的前缀名称，模块名 =
        strategyConfig.setRestControllerStyle(true); //设置是否启用Rest风格
        strategyConfig.setEntityLombokModel(true); //设置是否启用lombok
        mpg.setStrategy(strategyConfig);
//执行
        mpg.execute();
    }
}